// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;

namespace SnapObjects.Data
{
    /// <summary>
    ///     Provides methods to manage database transactions.
    /// </summary>
    public interface IAdoDbTransactionManager
    {
        /// <summary>
        ///     Starts a database transaction without specifying the isolation level (IsolationLevel.Unspecified).
        /// </summary>
        /// <returns>Returns an object representing the new transaction if succeeds.</returns>
        IAdoDbTransaction BeginTransaction();

        /// <summary>
        ///     Starts a database transaction with the specified isolation level.
        /// </summary>
        /// <param name="isolationLevel">The isolation level for the transaction.</param>
        /// <returns>Returns an object representing the new transaction if succeeds.</returns>
        IAdoDbTransaction BeginTransaction(IsolationLevel isolationLevel);

        Task<IAdoDbTransaction> BeginTransactionAsync(CancellationToken cancellationToken);

        Task<IAdoDbTransaction> BeginTransactionAsync(
            IsolationLevel isolationLevel, CancellationToken cancellationToken = default);

        /// <summary>
        ///     Uses a specified database transaction when no transaction is already started.
        /// </summary>
        /// <param name="transaction">The database transaction you want to use in the current database connection.</param>
        /// <returns>Returns an IAdoDbTransaction object that represents the new database transaction if succeeds.</returns>
        IAdoDbTransaction UseTransaction(DbTransaction transaction);
    }
}
